<script lang="ts" setup>
import type { InfraDatacenterTableApi } from '#/api/infra/db/table';

import { ref } from 'vue';

import { useVbenDrawer } from '@vben/common-ui';

import Fields from '../../tablefields/index.vue';

const formData = ref<InfraDatacenterTableApi.DatacenterTable>({});
const [Drawer, drawerApi] = useVbenDrawer({
  footer: false,
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = {} as InfraDatacenterTableApi.DatacenterTable;
      return;
    }
    // 加载数据
    const data = drawerApi.getData<InfraDatacenterTableApi.DatacenterTable>();
    if (!data || !data.id) {
      formData.value = data;
      return;
    }
    // 设置到 values
    formData.value = data;
  },
});
</script>

<template>
  <Drawer title="字段管理" class="w-[80%]">
    <Fields v-if="formData.id" :table-id="formData.id" />
  </Drawer>
</template>
